<?php

#################### - BEGIN LICENSE BLOCK - ################################
#																			#
# mobileDetect class														#
#																			#
# Copyright (C) Your Inspiration Web  										#
#																			#
#																			#
#																			#
# This program is free software: you can redistribute it and/or modify		#
# it under the terms of the GNU General Public License as published by		#
# the Free Software Foundation, either version 3 of the License, or			#
# (at your option) any later version.										#
#																			#
# This program is distributed in the hope that it will be useful,			#
# but WITHOUT ANY WARRANTY; without even the implied warranty of			#
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the				#
# GNU General Public License for more details.								#
#																			#
# You should have received a copy of the GNU General Public License			#
# along with this program.  If not, see http://www.gnu.org/licenses/		#
#																			#
#################### - END LICENSE BLOCK - ##################################



/**
 * mobileDetect
 *
 * @package none
 * @author Tarchini Maurizio
 * @metaAuthor YIW
 * @copyright 2011
 * @version 1.0.0 - alpha 1
 * @access public
 */
class mobileDetect
{
	/**
	* Name of mobile device
	* 
	* @since 1.0.0
	* @var string
	*/
	public $mobileName;
	
	/**
	* Is mobile device
	*
	* @since 1.0.0
	* @var bool
	*/
	public $isMobile;
	
	/** Is touchscreen device
	*
	* @since 1.0.0
	* @var bool
	*/
	public $isTouch;
	
	
	  /**
	   * mobileDetect::__construct()
	   *
	   * class constructor
	   * This method initializes the properties 
	   * and methods of the class
	   */
		public function __construct()
		{
			$this->isMobile = FALSE;
			$this->mobileName = FALSE;
			$this->isTouch = FALSE;
			$this->_mobile();
			$this->_touch();
		}
		
	  /**
	   * mobileDetect::_mobile()
	   *
	   * This method enhances the isMobile property to "TRUE" 
	   * if the request is from a mobile device. 
	   * The property mobileName is valued  with the device name
	   * @return void
	   */
		private function _mobile()
		{
			$list = file(dirname(__FILE__) . '/device_list.txt');
			
			foreach($list as $item)
			{	
				if(stripos($_SERVER['HTTP_USER_AGENT'], trim($item)))
				{
					$this->isMobile = TRUE;
					$this->mobileName = trim($item);
					break;
				}
			}
			return;
		}
		
	  /**
	   * mobileDetect::_touch()
	   * 
	   * This method enhances the isTouch property to "TRUE"
	   * if the device supports touchscreen
	   * @return void
	   */
		private function _touch()
		{
			$list = file(dirname(__FILE__) . '/touch_device_list.txt');
			
			foreach($list as $item)
			{	
				if(stripos($_SERVER['HTTP_USER_AGENT'], trim($item)))
				{
					$this->isTouch = TRUE;
					break;
				}
			}
			return;
		}
}

$mobileDetect = new mobileDetect();
?>


